package banking;

import java.util.Arrays;

public class ClassRoom {
	int id;
	public ClassRoom() {
       stulist = new Student[10]; //line 13 

	}
	public ClassRoom(int id) {
		this.id = id;
		stulist = new Student[10]; // line 8 if you don't add this to the constructor ,you have to allocate a number of student manually 
	}
	 public Student[] stulist ;
	
	public void addstu(Student stu) {
		for (int i = 0; i < stulist.length; i++) {
			if (i + 1 == stulist.length) {
				stulist = Arrays.copyOf(stulist, stulist.length + 1);
			}
			if (stulist[i] == null) {
				stulist[i] = stu;
				break;
			}

		}
	}

	public void showall() {
		for (int i = 0; i < stulist.length; i++) {// for each
			if (stulist[i] != null) {
				stulist[i].sayhi();
			}
		}
	}

	public int getClassNum() {
		int count = 0;
		for (int i = 0; i < stulist.length; i++) {
			if (stulist[i] != null) {
				count++;
			}
		}
		return count;
	}

	public void delstu(int id) {
		int index = -1;
		for (int i = 0; i < stulist.length; i++) {
			if (stulist[i] != null && stulist[i].id == id) {
				index = i;
				break;
			}
		} // end for
		if (index != -1) {
			for (int i = index + 1; i < stulist.length; i++) {
				stulist[i - 1] = stulist[i];
			}
			stulist[stulist.length - 1] = null;
		}

	}

}
